/*     */ package com.newcrm.webapi;
/*     */ 
/*     */ import com.newcrm.bean.User;
/*     */ import com.newcrm.db.CompanyExtManager;
/*     */ import com.newcrm.db.UserVOIPManager;
/*     */ import com.newcrm.exception.NotFoundException;
/*     */ import com.newcrm.util.MD5;
/*     */ import com.newcrm.util.ParameterUtil;
/*     */ import com.newcrm.util.Util;
/*     */ import com.newcrm.webapi.sub.ListAllCallRecords;
/*     */ import com.newcrm.webapi.sub.ListCallRecords;
/*     */ import com.newcrm.webapi.sub.SearchCustomerByPhone;
/*     */ import com.newcrm.webapi.sub.ShowPhoneArea;
/*     */ import com.newcrm.webapi.sub.UpdateVOIPSystemSetting;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintWriter;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import javax.servlet.RequestDispatcher;
/*     */ import javax.servlet.ServletException;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.jsoup.Connection;
/*     */ import org.jsoup.Jsoup;
/*     */ import org.jsoup.nodes.Document;
/*     */ 
/*     */ public class VOIP extends AbstractHttpServlet
/*     */ {
/*     */   private static final long serialVersionUID = -3933596928955890035L;
/*  38 */   private static Logger logger = Logger.getLogger(VOIP.class.getName());
/*     */ 
/*     */   public void doGet(HttpServletRequest request, HttpServletResponse response)
/*     */     throws ServletException, IOException
/*     */   {
/*  61 */     if (!checkLogin(request)) {
/*  62 */       super.showLoginPage(request, response);
/*  63 */       return;
/*     */     }
/*  65 */     String url = request.getRequestURI();
/*     */ 
/*  67 */     String[] param = ParameterUtil.getParameters(url, getTagkey());
/*  68 */     User user = super.getLoginUser(request);
/*     */     try
/*     */     {
/*  71 */       if ((param == null) || (param.length == 0)) {
/*  72 */         super.doGet(request, response);
/*  73 */         return;
/*     */       }
/*     */ 
/*  76 */       if (param.length == 1)
/*     */       {
/*  78 */         if ("account".equals(param[0])) {
/*  79 */           String appId = Util.getURLParameter(request
/*  80 */             .getParameter("appId"));
/*  81 */           String date = Util.date2Str(new Date());
/*  82 */           String sign = MD5.getMD5(appId + "_qikebao_" + date);
/*     */ 
/*  84 */           StringBuffer searchUrl = new StringBuffer();
/*  85 */           searchUrl
/*  86 */             .append("http://ucpaas.qikebao.com/account?appId=")
/*  88 */             .append(URLEncoder.encode(appId, "UTF-8"))
/*  89 */             .append("&sign=")
/*  90 */             .append(URLEncoder.encode(sign, "UTF-8"))
/*  91 */             .append("&date=")
/*  92 */             .append(URLEncoder.encode(date, "UTF-8"));
/*     */ 
/*  94 */           response.setContentType("text/html;charset=utf-8");
/*  95 */           PrintWriter out = response.getWriter();
/*  96 */           Document doc = null;
/*     */           try {
/*  98 */             doc = Jsoup.connect(searchUrl.toString())
/*  99 */               .timeout(30000).get();
/* 100 */             out.println(doc.text());
/*     */           }
/*     */           catch (Exception e) {
/* 103 */             logger.warn("get voip account failed", e);
/* 104 */             return;
/*     */           }
/* 106 */           out.flush();
/* 107 */           out.close();
/* 108 */           return;
/*     */         }
/*     */ 
/* 112 */         if ("callPhone".equals(param[0])) {
/* 113 */           String appId = Util.getURLParameter(request
/* 114 */             .getParameter("appId"));
/* 115 */           String clientId = Util.getURLParameter(request
/* 116 */             .getParameter("clientId"));
/* 117 */           String tel = Util.getURLParameter(request
/* 118 */             .getParameter("tel"));
/*     */ 
/* 120 */           if ((tel == null) || (tel.trim().length() == 0)) {
/* 121 */             super.showErrorMessage(response, "SIP电话呼出失败！");
/* 122 */             return;
/*     */           }
/*     */ 
/* 125 */           if (tel.contains("-")) {
/* 126 */             tel = tel.replaceAll("-", "");
/*     */           }
/*     */ 
/* 129 */           String date = Util.date2Str(new Date());
/* 130 */           String sign = MD5.getMD5(appId + "_qikebao_" + date);
/*     */ 
/* 133 */           StringBuffer searchUrl = new StringBuffer();
/* 134 */           searchUrl
/* 135 */             .append("http://ucpaas.qikebao.com/call?appId=")
/* 137 */             .append(URLEncoder.encode(appId, "UTF-8"))
/* 138 */             .append("&sign=")
/* 139 */             .append(URLEncoder.encode(sign, "UTF-8"))
/* 140 */             .append("&date=")
/* 141 */             .append(URLEncoder.encode(date, "UTF-8"))
/* 142 */             .append("&clientId=")
/* 143 */             .append(URLEncoder.encode(clientId, "UTF-8"))
/* 144 */             .append("&tel=")
/* 145 */             .append(URLEncoder.encode(tel, "UTF-8"));
/*     */ 
/* 147 */           response.setContentType("text/html;charset=utf-8");
/* 148 */           PrintWriter out = response.getWriter();
/* 149 */           Document doc = null;
/*     */           try {
/* 151 */             doc = Jsoup.connect(searchUrl.toString())
/* 152 */               .timeout(30000).get();
/* 153 */             out.println(doc.text());
/*     */           }
/*     */           catch (Exception e) {
/* 156 */             logger.warn("VOIP SIP Call warning", e);
/* 157 */             super.showErrorMessage(response, "SIP电话呼出失败！");
/* 158 */             return;
/*     */           }
/* 160 */           out.flush();
/* 161 */           out.close();
/* 162 */           return;
/*     */         }
/*     */ 
/* 165 */         if ("setting".equals(param[0]))
/*     */         {
/* 167 */           CompanyExtManager manager = new CompanyExtManager();
/* 168 */           String userName = manager.getFieldValue(user.companyId, 
/* 169 */             4);
/* 170 */           if (userName == null) {
/* 171 */             userName = "";
/*     */           }
/* 173 */           String userPwd = manager.getFieldValue(user.companyId, 
/* 174 */             5);
/* 175 */           if (userPwd == null) {
/* 176 */             userPwd = "";
/*     */           }
/* 178 */           String serverIP = manager.getFieldValue(user.companyId, 
/* 179 */             6);
/* 180 */           if (serverIP == null) {
/* 181 */             serverIP = "";
/*     */           }
/*     */ 
/* 184 */           request.setAttribute("voip_name", userName);
/* 185 */           request.setAttribute("voip_pwd", userPwd);
/* 186 */           request.setAttribute("voip_ip", serverIP);
/*     */ 
/* 189 */           UserVOIPManager userVOIPManager = new UserVOIPManager();
/* 190 */           List seats = userVOIPManager
/* 191 */             .getUsersVOIPSeatInfo(user.companyId);
/*     */ 
/* 193 */           request.setAttribute("seats", seats);
/* 194 */           request.getRequestDispatcher("/voip_setting.jsp").forward(
/* 195 */             request, response);
/* 196 */           return;
/*     */         }
/*     */ 
/* 200 */         if ("search".equals(param[0])) {
/* 201 */           new ListAllCallRecords(this).parse(request, response);
/* 202 */           return;
/*     */         }
/*     */ 
/* 206 */         if ("searchCustomer".equals(param[0])) {
/* 207 */           new SearchCustomerByPhone(this).parse(request, response);
/* 208 */           return;
/*     */         }
/*     */ 
/* 212 */         if ("phonearea".equals(param[0])) {
/* 213 */           new ShowPhoneArea(this).parse(request, response);
/* 214 */           return;
/*     */         }
/*     */ 
/* 217 */         return;
/*     */       }
/*     */ 
/* 221 */       if ((param.length == 2) && ("setting".equals(param[0])) && 
/* 222 */         ("update".equals(param[1])))
/*     */       {
/* 225 */         if ((!user.isAdmin) && (!user.isGroupAdmin)) {
/* 226 */           request.getRequestDispatcher("/nopermission.jsp")
/* 227 */             .forward(request, response);
/* 228 */           return;
/*     */         }
/*     */         try
/*     */         {
/* 232 */           new UpdateVOIPSystemSetting(this).parse(request, response);
/*     */         } catch (NotFoundException e) {
/* 234 */           request.getRequestDispatcher("/errorpage.jsp").forward(
/* 235 */             request, response);
/* 236 */           return;
/*     */         }
/*     */ 
/* 239 */         return;
/*     */       }
/*     */     } catch (NotFoundException e) {
/* 242 */       request.getRequestDispatcher("/nopermission.jsp").forward(
/* 243 */         request, response);
/* 244 */       return;
/*     */     }
/* 246 */     super.doGet(request, response);
/*     */   }
/*     */ 
/*     */   protected String getTagkey()
/*     */   {
/* 251 */     return "/voip";
/*     */   }
/*     */ 
/*     */   protected AbstractAction getAddAction()
/*     */   {
/* 256 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getListAction()
/*     */   {
/* 261 */     return new ListCallRecords(this);
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAddPageAction()
/*     */   {
/* 266 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getUpdateAction(String id)
/*     */   {
/* 271 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowConfirmDestroyAction(String id)
/*     */   {
/* 276 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getDeleteAction(String id)
/*     */   {
/* 281 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowAction(String id)
/*     */   {
/* 286 */     return null;
/*     */   }
/*     */ 
/*     */   protected AbstractAction getShowUpdatePageAction(String id)
/*     */   {
/* 291 */     return null;
/*     */   }
/*     */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.VOIP
 * JD-Core Version:    0.6.1
 */